package com.acane.instagram.feature.post

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument

const val POST_ROUTE = "post"

const val POST_ROUTE_WITH_USER_ID = "user_id"

const val POST_ROUTE_WITH_POST_POSITION = "post_position"

fun NavGraphBuilder.postScreen(
    navController: NavHostController,
    toProfile: (String) -> Unit,
) {
    composable(
        "$POST_ROUTE/{$POST_ROUTE_WITH_USER_ID}/{$POST_ROUTE_WITH_POST_POSITION}",
        arguments = listOf(
            navArgument(POST_ROUTE_WITH_USER_ID) {type = NavType.StringType},
            navArgument(POST_ROUTE_WITH_POST_POSITION) {type = NavType.IntType}
        )
    ) {
        backStackentry ->
        val userId = backStackentry.arguments!!.getString(POST_ROUTE_WITH_USER_ID)
        val postPosition = backStackentry.arguments!!.getInt(POST_ROUTE_WITH_POST_POSITION)
        UserPostList(
            toProfile = toProfile,
            navController = navController,
            userId = userId,
            postPosition = postPosition,
        )
    }
}

fun NavController.navigateToPost(userId: String, postPosition: Int): Unit {
    navigate("$POST_ROUTE/$userId/$postPosition")
}